//Erik Wright
//marionette.h
//11-4-2013

/*
this file describes the structure of the humainoid_marionette
 class which provides essential functions to ensure that the 
marionette or the controller is not damaged and is able to 
perform machine learning where the puppet will learn to walk, 
run, dance, etc.

The below strucure outlines a series of vertical controlers, horizontal body controllers,
and positional controllers.  The vertical controlers and positional controllers are continuous
 rotation servos; the horizontal controlers are direct angle controlers.  These should ultimately
not matter as the genetic algorithm should allow each controller to evolve its motions independantly
and thus ensure the overall motion of the robot.

Here, I have created an array of lists of controller commands.
I have also created a matrix that shows the relationship of 
each controller to each other controller.  It is used as a 
refference for maximum distances between linkages on the puppet.
Then there is a simmilar matrix that holds the current
displacements of all linkages from their origin.
*/



#include "conrot_servo.h"

#define NUM_CHANNELS 15


class humanoid_marionette 
{
	private:
		int rating;	//current generation rating
		float[NUM_CHANNELS][NUM_CHANNELS] error;	//error between nodes
		float[NUM_CHANNELS][NUM_CHANNELS] cur_state;	//current state matrix
		float[NUM_CHANNELS][NUM_CHANNELS] maximums;	//maximums between linkages
		conrot_server[NUM_CHANNELS] controller_array;	//expands to any number of controllers 
		void correct_slack(int channel_a, int channel_b);	//change the 'slack' line command
		void correct_stiff(int channel_a, int channel_b);	//change the 'stiff' line command


	public:
		~humanoid_marionette();		//class destructor
		humanoid_marionette();		//default constructor
		humanoid_marionette(int);	//loaded constructor | use like default
		humanoid_marionette(const humanoid_marionette*&);	//copy constructor
		humanoid_marionette(char* fname);	//create class from file in current working directory
		bool error_check();		//check entire motion list array for slack lines
		int play_motion();		//plays the entire motion list arry on puppet
		int to_file(char* fname);	//write the entire current state of the class to a file
		void display_sequence();	//displays entire chromosome
		void display_errors();		//display current known errors
		void display_current_disp();	//display the current displacement state 
		void display_current_velo();	//display the current velocity state
		void give_rating(int);		//gives a rating to chromo
		void binary_twist(humanoid_marionette *&);	//performs a binary twist
		void binary_twist_rand(humanoid_marionette *&);	//performs random binary twists 
		void average_twist(humanoid_marionette *&);	//performs twist as average
		void weighted_average_twist(humanoid_marionette *&);	//performs weighted average twist
		void fuzzy_twist(humanoid_marionette *&);	//performs a fuzzy twist based on rating
};	
